<!DOCTYPE html>
<html>

<head lang="en">
    <title>游记评论</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            var params = getParams();
            if (params) {
                $.get("/travelComments/" + params.travelCommentId, function (data) {
                    //点评作者id
                    var authorId = data.result.user.id;
                    //登录的user
                    var user = JSON.parse(sessionStorage.getItem("user"));
                    $(".container").renderValues(data, {
                        // {
                        // //图片回显
                        // getImage:function (item, value) {
                        //     //把图片的地址切分
                        //     var url = value.split(";");
                        //     //分割时多了一个,长度要减一
                        //     for (var i=0;i<url.length-1;i++)
                        //     {
                        //         $(item).append("<li><img src='"+url[i]+"'></img></li>")
                        //     }
                        // },
                        getHref: function (item, value) {
                            var href = $(item).attr("href");
                            $(item).attr("href", href + value);
                        }
                    });
                    $("#count").renderValues(data);
                    console.log(data);

                    //查询是否关注
                    if (user) {
                        $.get('/users/' + user.id + '/' + authorId, function (data) {
                            if (user.id == authorId) {
                                $('#followBtn').html('自己');
                            } else {
                                if (data) {
                                    $('#followBtn').html('取关');
                                } else {
                                    $('#followBtn').html('关注');
                                }
                            }
                        });
                    } else {
                        $('#followBtn').html('关注');
                    }

                    //关注按钮点击事件
                    $('#followBtn').click(function () {
                        if (user) {
                            if (user.id == authorId) {
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '关注自己干哈?',
                                    autoClose: 1000,
                                    position: 'center'  // center: 居中; bottom: 底部
                                });
                            } else {
                                if ($('#followBtn').html() == '取关') {
                                    $("#followBtn").html("关注");
                                    $(document).dialog({
                                        type: 'notice',
                                        infoText: '取消关注√',
                                        autoClose: 1000,
                                        position: 'center'  // center: 居中; bottom: 底部
                                    });
                                    $.ajax({
                                        url: "/users/" + user.id + "/" + authorId,
                                        method: "delete"
                                    })
                                } else {
                                    $('#followBtn').html('取关');
                                    $(document).dialog({
                                        type: 'notice',
                                        infoText: '关注√',
                                        autoClose: 1000,
                                        position: 'center'  // center: 居中; bottom: 底部
                                    });
                                    $.ajax({
                                        url: "/users/" + user.id + "/" + authorId,
                                        method: "post"
                                    });
                                }
                            }
                        } else {
                            window.location.href = 'login.html';
                        }

                    });
                });
                //根据当前评论的id查询评论下的所有回复评论
                $.get("/travelCommentRes/" + params.travelCommentId, function (data) {
                    $("#commentRe").renderValues({list: data.result}, {
                        getHreff: function (item, value) {
                            var href = $(item).attr("href");
                            $(item).attr("href", href + value);
                        }
                    });
                })
                //点击添加你的评论按钮点击事件
                $(".operation").click(function () {
                    window.location.href = '/mine/addTravelCommentRe.html?travelCommentId=' + params.travelCommentId;
                })

            }
        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left "></i></span>
            </a>
        </div>
        <div class="col">
            <span>评论详情</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<div class="comment">
    <div class="container ">
        <div class="row">
            <div class="col-2 comment-head">
                <a href="../userProfiles.html?id=" render-key="result.user.id" render-fun="getHref">
                    <img class="rounded-circle" render-src="result.user.headImgUrl">
                </a>
                <button class="btn btn-success" id="followBtn"></button>
            </div>
            <div class="col">
                <a href="../userProfiles.html?id=" render-key="result.user.id" render-fun="getHref">
                    <span class="comment-star" render-html="result.user.nickName"></span>
                </a>
                <span class="comment-date" render-html="result.commentTime"></span>
                <div class="comment-content">
                    <p render-html="result.commentContent"></p>
                </div>
                <!--<ul class="comment-img" render-key="imgUrls" render-fun="getImage">-->

                <!--</ul>-->
                <!--这个界面就不回显当前游记信息了-->
                <!--<div class="comment-link">-->
                <!--<a href="../strategyCatalogs.html?strategyId=" render-key="strategy.id" render-fun="getHref">-->
                <!--<img  render-src="result.travel.coverUrl"> <span render-html="result.travel.title"></span>-->
                <!--<i class="fa fa-angle-right fa-2x"></i>-->
                <!--</a>-->
                <!--</div>-->
            </div>
        </div>
    </div>

    <div class="count d-flex justify-content-between" id="count">

        <div class="p-2">评论<span render-html="result.replyCount"></span></div>
        <!--<div class="p-2">赞<span>0</span></div>-->

    </div>

</div>
<!--<div class="comment-list">-->
<!--快来发表你的评论吧-->
<!--</div>-->
<div id="commentRe">
    <div render-loop="list">
        <div class="container row comment">
            <div class="col-2 comment-head">
                <a href='../userProfiles.html?id=' render-key="list.user.id" render-fun="getHreff">
                    <img class="rounded-circle"
                         render-src="list.user.headImgUrl">
                </a>
            </div>
            <div class="col comment-right">
                <a href='../userProfiles.html?id=' render-key="list.user.id" render-fun="getHreff">
                    <p class="authorName"><span render-html="list.user.nickName"></span>
                        <span class="comment-date" render-html="list.createTime"></span>
                    </p></a>

                <div class="comment-content">
                    <p render-html="list.content"></p>
                </div>
                <!--<div class="d-flex icon">
                    <a href="mine/strategyComment.html" >
                        <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                        <i class="fa fa-thumbs-o-up" > <span >0</span> </i>
                    </a>
                </div>-->
            </div>
        </div>
    </div>
</div>

<div class="operation">
    <div class="d-flex justify-content-between">
        <div class="p-2"><i class="fa fa-commenting-o"></i> 添加你的评论</div>
    </div>
</div>


</body>

</html>